package com.example.androidkt.fifth

import android.util.Log
import androidx.lifecycle.ViewModel

class ViewModelOne : ViewModel() {
    val Tag = this.javaClass.simpleName

    init {
        Log.d(Tag, "初始化 ViewModelOne 创建")
    }

    fun getNow(): String {
        return "ViewModelOne ${System.currentTimeMillis()}"
    }

    //当activity销毁时调用，防止内存泄漏
    override fun onCleared() {
        super.onCleared()
        Log.d(Tag, "ViewModelOne onCleared")
        Log.d(Tag, "ViewModelTwo onCleared")
    }
}

class ViewModelTwo(val count: Int) : ViewModel() {
    val Tag = this.javaClass.simpleName

    init {
        Log.d(Tag, "初始化 ViewModelTwo 创建")
    }

    fun getNow(): String {
        return "ViewModelTwo ${System.currentTimeMillis()}"
    }

    //当activity销毁时调用，防止内存泄漏
    override fun onCleared() {
        super.onCleared()
        Log.d(Tag, "ViewModelTwo onCleared")
    }
}
